<?php
include 'DBManager.class.php';

$title=mysql_escape_string( $_GET['title'] );
$year = mysql_escape_string( $_GET['year'] );
$released = mysql_escape_string( $_GET['released'] );
$rated = mysql_escape_string( $_GET['rated'] );
$genre =  isset ($_GET['genre']) ? $_GET['genre'] : 'noGenre';
$director = mysql_escape_string( $_GET['director'] );
$writer = mysql_escape_string( $_GET['writer'] );
$actors = mysql_escape_string( $_GET['actors'] );
$plot = isset ($_GET['plot']) ?  mysql_escape_string( $_GET['plot'] ) : 'N/A';
$cover =  isset ($_GET['cover']) ?  mysql_escape_string( $_GET['cover'] ) : 'N/A';
$runtime = mysql_escape_string( $_GET['runtime'] );
$originId=$_GET['idODB'];
$genreStr = '';

if ($genre != 'noGenre')
	foreach($genre as &$k){ 
		$genreStr .= $k.", ";
	}
	
$genreStr =  substr( $genreStr, 0, strlen($genreStr)-2);

if(strlen($genreStr)<=0){
	$genreStr = 'N/A';
}

$db = new DBManager ( 'localhost',  'root',  '',  'iumus' );
$query="INSERT INTO movie (id, title, year, rated, released, genre, director, writer, actors, plot, cover, runtime, rating, votes, id_origin) VALUES 
( '".$_GET['idDB']."'  '".$title."', '".$year."', " . "'".$rated."', " . "'".$released."', " . "'".$genreStr."', " . "'".$director."', " . "'".$writer."', " . "'".$actors."', " . "'".$plot."', " . "'".$cover."', '" . $runtime."', "
. "0, 0, "."'".$originId."');";
$db->executeQuery ($query);
header ("Location: ../../wp-admin/index.php");
?>